﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LuatChoi;

namespace Client
{
    public class TinhToan
    {
        private const int Vien = 13;
        private const int A = 49;
        public static Rectangle ChuyenThanhToaDoHinh(int x, int y, Phe phe)
        {


            var r = new Rectangle(0, 0, A, A);
            switch (phe)
            {
                case Phe.Trang:
                    r.X = Vien + x * 50;
                    r.Y = Vien + (7 - y) * 50;
                    return r;
                case Phe.Den:
                    r.X = Vien + (7 - x) * 50;
                    r.Y = Vien + y * 50;
                    return r;
                default:
                    return new Rectangle();
            }
        }

        public static Vector ChuyenThanhToaDoBanCo(int x, int y, Phe phe)
        {
            var v = new Vector(-1, -1);
            switch (phe)
            {
                case Phe.Trang:
                    v.X = (x - Vien) / A;
                    v.Y = 7 - (y - Vien) / 50;
                    break;
                case Phe.Den:
                    v.X = 7 - (x - Vien) / A;
                    v.Y = (y - Vien) / A;
                    break;
            }
            if (v.X >= 0 && v.X <= 7 && v.Y >= 0 && v.Y <= 7)
                return v;
            return null;
        }

        public static Image LayHinh(QuanCo quan)
        {
            if (quan.Mau == Phe.Trang)
            {
                if (quan is Tot)
                    return Properties.Resources.tot;
                if (quan is Ma)
                    return Properties.Resources.ma;
                if (quan is Tuong)
                    return Properties.Resources.tuong;
                if (quan is Xe)
                    return Properties.Resources.xe;
                if (quan is Hau)
                    return Properties.Resources.hau;
                if (quan is Vua)
                    return Properties.Resources.vua;
            }
            else
            {
                if (quan is Tot)
                    return Properties.Resources.totden;
                if (quan is Ma)
                    return Properties.Resources.maden;
                if (quan is Tuong)
                    return Properties.Resources.tuongden;
                if (quan is Xe)
                    return Properties.Resources.xeden;
                if (quan is Hau)
                    return Properties.Resources.hauden;
                if (quan is Vua)
                    return Properties.Resources.vuaden;
            }
            return new Bitmap(0, 0);
        }

        public static string TinhThoiGian(int x)
        {
            int giay = x % 60;
            x /= 60;
            int phut = x % 60;
            return string.Format("{0}:{1}", phut.ToString().PadLeft(2, '0'), giay.ToString().PadLeft(2, '0'));
        }
    }
}
